package com.cwm.test.single.lazy;

/**
 * ClassPath:LazystaticInnerclasssingleton.class
 * LazystaticInnerclasssingletongLazyHolder.class
 * * 优点:写法优雅，
 * * 利用了Iava本身语法特点，性能高，避免了内存浪费，不被反射破坏
 * * 缺点: 不优雅
 */
public class LazystaticInnerclasssingleton {

    private LazystaticInnerclasssingleton() {
        // 这样定义，就不能被破环
        if (LazyHolder.INSTANCE!=null){
            throw new RuntimeException("不能被访问");
        }
    }

    private static LazystaticInnerclasssingleton getInstance() {
        return LazyHolder.INSTANCE;
    }

    private static class LazyHolder {
        private static final LazystaticInnerclasssingleton INSTANCE = new LazystaticInnerclasssingleton();
    }
}